/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import model.States;

/**
 *
 * @author Adriano
 */
public class StatesDAO implements DAO {

    private DataSource dataSource;

    public StatesDAO() {
        dataSource = new DataSource();
    }

    public void closeDAO() {
        dataSource.closeConnection();

    }

    public void create(Object o) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    public void delete(Object o) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    public void update(Object o) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    public Object read(Object o) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    public Object ReadAllStates() {

        try {
            String sql = "select * from states";

            PreparedStatement ps = dataSource.getConnection().prepareStatement(sql);

            ArrayList<States> listStates = new ArrayList<States>();
            ResultSet rs = ps.executeQuery(sql);

            while (rs.next()) {
                States item = new States();
                item.setId(rs.getInt("idStates"));
                item.setUF(rs.getString("UF"));
                listStates.add(item);
            }
            return listStates;
        } catch (SQLException e) {
            System.err.println("STATES.read() " + e.getMessage());
            return null;
        }
    }

}
